package pattern.login.bridge.function;

import com.alibaba.fastjson.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import pattern.entity.UserInfo;
import pattern.login.bridge.abst.factory.RegisterLoginComponentFactory;
import pattern.service.UserRepository;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Component
public class RegisterLoginByGitee extends AbstractRegisterLoginFunc implements RegisterLoginFuncInterface {


    @Autowired
    private UserRepository userRepository;

    @PostConstruct
    private void initFuncMap() {
        RegisterLoginComponentFactory.funcMap.put("GITEE", this);
    }

    @Override
    public String login3rd(HttpServletRequest request) {
        return "login3rd ";
    }

    private String autoRegister3rdAndLogin(String userName, String password) {
        //如果第三方账号已经登录过，则直接登录
        if(super.commonCheckUserExists(userName, userRepository)) {
            return super.commonLogin(userName, password, userRepository);
        }
        UserInfo userInfo = new UserInfo();

        //如果第三方账号是第一次登录，先进行“自动注册”
        super.commonRegister(userInfo, userRepository);
        //自动注册完成后，进行登录
        return super.commonLogin(userName, password, userRepository);
    }
}
